<?php

namespace Model;

use Config\Cfg;
use GatewayWorker\Lib\Gateway;
use Extension\Tools;

abstract class RoomBase {
	/**
	 * 房间ID
	 *
	 * @var string
	 */
	public $m_RoomId;
	/**
	 * 所属大区
	 *
	 * @var int
	 */
	public $m_ZoneId;
	/**
	 * 房号
	 * 
	 * @var unknown
	 */
	public $m_RoomNum;
	/**
	 * 房名
	 *
	 * @var unknown
	 */
	public $m_RoomName;
	/**
	 * 房间类型
	 *
	 * @var unknown
	 */
	public $m_RoomType;
	/**
	 * 玩家进入房间
	 *
	 * @param User $user        	
	 */
	abstract public function mb_UserIn($user);
	/**
	 * 玩家退出房间
	 *
	 * @param User $user        	
	 */
	abstract public function mb_UserOut($user);
	/**
	 * 玩家消息进入
	 *
	 * @param User $user        	
	 * @param json $data        	
	 */
	abstract public function mb_DataIn($user, $data);
	/**
	 * 发送数据
	 *
	 * @param User $user        	
	 * @param string $data        	
	 */
	public function mb_DataOut($user, $recNo, $result, $data) {
		$repData = new \stdClass ();
		$repData->m_RecNo = $recNo;
		$repData->m_Result = $result;
		$repData->m_Data = $data;
		$repData->m_Sign = md5 ( $recNo . $result . $data . Cfg::MSG_MD5 );
		if ($user->m_ClientId != '') {
			$send = json_encode ( $repData );
			Tools::mb_LogResult ( "Data Out : [ $user->m_Name , $recNo , $result, $send ]" );
			Gateway::sendToClient ( $user->m_ClientId, $send );
		} else {
			Tools::mb_LogResult ( "$user->m_Name ClientId Is Empty!!!" );
		}
	}
	/**
	 * 类型：自由场
	 */
	public const TYPE_FREE = 1;
	/**
	 * 类型：好友房
	 */
	public const TYPE_BUDDY = 2;
	/**
	 * 类型：俱乐部房
	 */
	public const TYPE_CLUB = 3;
}